package com.lazyben.router;

import com.lazyben.model.Message;
import com.lazyben.server.ChannelHandlerContextHolder;
import com.lazyben.server.MessageContainer;
import com.lazyben.server.PushServer;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.stereotype.Component;

@Component
public class PushServerRouter extends Thread {

    @Override
    public void run() {
        while (true) {
            Message message = MessageContainer.get();
            route(message);
        }
    }

    public void route(Message message) {
        ChannelHandlerContext channelCtx = ChannelHandlerContextHolder.getChannelCtx(message.getClientId());
        PushServer.send(message, channelCtx);
    }
}
